// "Copyright [2021] <Copyright Shengkai Lin>"

#ifndef CLUSTER_NETWORK_CONTROLLER_NETWORK_ROUTING_H_
#define CLUSTER_NETWORK_CONTROLLER_NETWORK_ROUTING_H_

#include <unordered_map>
#include <map>
#include <utility>
#include <string>
#include "cluster/basic/ai_sim.h"
#include "cluster/network_controller/topo_manager/topo_manager.h"
#include "cluster/dispatcher/dispatcher.h"
#include "inet/src/inet/node/inet/Router.h"
#include "path_manager/OpticalPathManager.h"
#include "cluster/roce/RoceMsg_m.h"
#include "cluster/dispatcher/flowparser.h"

namespace ai_sim {
class NetworkRouting :public omnetpp::cSimpleModule {
 private:
    TopoManager* topos;
    ClusterType clustertype;
    OpticalPathManager optical_path_manager_;
    std::map<pair<int, int>, int> current_flow_count;
    std::map<pair<int, int>, int> record_flow_count;
    // record whether the leaf spine has been given the route
    bool needStaticLeaf;
    std::map<int, bool> visitedLeaf;
 public:
    void initialize() override;
    // Used when we need to alloc a batch of routes
    // to multi switches
    static bool selectByName(omnetpp::cModule *mod, void*);
    void allocRoutes(const map<int, RouteVec>&);
    void allocRoutes(FlowMsg *f_msg);
    void alloctxtRoutes(const map<int, RouteVec>& routes_map);

    void gen_route(taskboard&, RouteAlgorithm*);
    // Route the flow with compound in path
    void gen_txt_route(map<int, RouteVec>&, DetailFlow&);
    void handleMessage(omnetpp::cMessage *msg) override;
};
}  // namespace ai_sim

#endif  // CLUSTER_NETWORK_CONTROLLER_NETWORK_ROUTING_H_
